<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>worker - 非跨越 - 单独线程计算</title>
	</head>

	<body>
		<p id="count">count：0</p>
		<input type="button" value="开始计算" id="btn" />

		<script>
			const myWorker = new Worker('./worker.js')
			const btn = document.querySelector('#btn')
			const countRef = document.querySelector('#count')
			btn.addEventListener('click', () => {
				myWorker.postMessage('开始计算')
			})

			myWorker.onmessage = (e) => {
				console.log('receive worker 计算的值', e)
				countRef.textContent = 'count：' + e.data
			}
		</script>
	</body>
</html>
